package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.Hotel;
import cn.wolfcode.trip.base.mapper.HotelMapper;
import cn.wolfcode.trip.base.query.HotelQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IHotelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelServiceImpl implements IHotelService{
    @Autowired
    private HotelMapper hotelMapper;

    @Override
    public void saveOrUpdate(Hotel hotel) {

        if(hotel.getId() == null){
            hotelMapper.insert(hotel);
        }else {
            hotelMapper.updateByPrimaryKey(hotel);
        }
    }

    @Override
    public PageInfo query(HotelQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Hotel> hotels = hotelMapper.queryForList(qo);
        return new PageInfo(hotels);
    }

    @Override
    public List<Hotel> listCommendHotels(Integer state) {
        List<Hotel> list= hotelMapper.listCommendHotels(state);
        return list;
    }

    @Override
    public Hotel queryHotelById(Long id) {
        Hotel hotel = hotelMapper.selectByPrimaryKey(id);
        return hotel;
    }

}
